<template>
	<view class="page-container return-order-container">
		<view class="card-box display-flex space-between">
			<view class="goods-image">
				<lazy-image :src="$img_base_url(info.detail.image)"></lazy-image>
			</view>
			<view class="goods-info">
				<view class="display-flex alig space-between">
					<text style="font-weight: bold;font-size: 34rpx;color: #333333;">{{info.detail.name}}</text>
					<text style="font-weight: 900;font-size: 34rpx;color: #FF2E2E;">￥{{info.detail.price}}</text>
				</view>
				<!-- <view class="display-flex alig space-between margin-top-40" style="font-weight: bold;font-size: 28rpx;color: #333333;">
					<text>规格名称规格名称</text>
					<text>x1</text>
				</view> -->
			</view>
		</view>
		<view class="card-box mt-20">
			<view class="title">
				<text>退款信息</text>
			</view>
			<view class="display-flex alig space-between mt-20" style="font-weight: bold;font-size: 30rpx;color: #000000;">
				<view class="">
					<text>退款原因</text>
				</view>
				<view class="display-flex alig" @click="showReturnPopup">
					<text>{{select_r.name||'请选择'}}</text>
					<view class="icon-right">
						<image :src="$img_path('/home/icon-right.png')" mode="widthFix"></image>
					</view>
				</view>
			</view>
		</view>
		<view class="card-box mt-20">
			<view class="display-flex alig space-between" style="font-weight: bold;font-size: 30rpx;">
				<text style="color: #000;">申请退款金额</text>
				<view class="display-flex alig">
					<text style="color: #FF2E2E;">¥ {{info.payprice}}</text>
					<view style="width: 36rpx; height: 36rpx; margin-left: 10rpx;">
						<image :src="$img_path('/home/order/icon-edit.png')" mode="widthFix"></image>
					</view>
				</view>
			</view>
			<view class="mt-20 display-flex flex-end">
				<!-- <text style="font-weight: 400;font-size: 26rpx;color: #000000;">¥ 130.00</text> -->
				<input type="text" style="width: 100%;text-align: right;" v-model="form.refund_price" :placeholder="'最多可输入服务金额¥ '+info.payprice" placeholder-style="font-weight: 400;font-size: 26rpx;color: #000000;text-align:right;" />
			</view>
		</view>
		<view class="mt-20">
			<text style="font-weight: bold;font-size: 30rpx;color: #000000;">售后完成后，以下资产预计将被退回</text>
		</view>
		<view class="card-box mt-20">
			<view class="display-flex alig space-between" style="font-weight: bold;font-size: 30rpx;color: #333;">
				<view class="">
					<text>退优惠劵</text>
				</view>
				<view class="display-flex alig">
					<text v-if="info.coupon_id">1张</text>
					<text v-else>无	</text>
					<!-- <view class="icon-right">
						<image :src="$img_path('/home/icon-right.png')" mode="widthFix"></image>
					</view> -->
				</view>
			</view>
		</view>
		<view class="card-box mt-20">
			<view class="title">
				<text>上传凭证</text>
				<text style="font-weight: 400;font-size: 28rpx;color: #000000; margin-left: 26rpx;">选填</text>
			</view>
			<view class="upload-list mt-20">
				<view class="upload-image" v-for="(item,i) in images" :key="i">
					<image class="del" @click="delimg(i)" :src="$img_path('/course/city_1.png')" mode="widthFix"></image>
					<image :src="$img_base_url(item)" mode="widthFix"></image>
				</view>
				<view class="upload-image" @click="uploadPZ" v-if="images.length<4">
					<image :src="$img_path('/home/order/upload-3.png')" mode="widthFix"></image>
				</view>
			</view>
		</view>
		<view class="card-box mt-20">
			<view class="title">
				<text>补充描述</text>
				<text style="font-weight: 400;font-size: 28rpx;color: #000000; margin-left: 26rpx;">选填</text>
			</view>
			<view class="textarea mt-20">
				<textarea style="height: 208rpx; width: 100%;background: #F8F8F8;border-radius: 20rpx; padding:18rpx 22rpx; box-sizing: border-box;" v-model="form.content" placeholder="请输入取消的原因" />
			</view>
		</view>
		<view class="fixed-box">
			<view class="fixed-btn common-btn-bg-color" @click="submit">
				<text>提交</text>
			</view>
		</view>
		
		<!-- 退款原因弹窗 -->
		<returnRemarkPopup ref="returnRemarkPopupRef" />
		<!-- 退款原因弹窗 -->
		<retPayPopupVue ref="retPayPopupRef" @confirm="confirm" />
		<!-- 退款成功弹窗 -->
		<uni-popup ref="retSuccessPopupRef" type="center" background-color="#fff" border-radius="20rpx">
			<view class="success-popup">
				<view class="title display-flex alig center">
					<text>提交退款申请成功</text>
				</view>
				<view class="content display-flex alig center">
					<text>请耐心等待平台的审核</text>
				</view>
				<view class="confirm-btn-box display-flex alig center">
					<view class="confirm-btn common-btn-bg-color" @click="closeRetSuccessPopup">
						<text>好的</text>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import returnRemarkPopup from "../../components/return-remark-popup/return-remark-popup.vue"
	import retPayPopupVue from '../../components/ret-pay-popup/ret-pay-popup.vue'
	import { upload } from '@/utils/api/public.js'
	import { refundorder } from '@/utils/api/serviceApi.js'
	const FormData = require('@/utils/formdata/index.js')
	export default {
		components: {
			returnRemarkPopup,
			retPayPopupVue
		},
		onLoad(options) {
			// this.$refs.retPayPopupRef.open()
			// this.$refs.returnRemarkPopupRef.open()
			// this.$refs.retSuccessPopupRef.open()
			this.info = JSON.parse(options.info)
		},
		/**
		 * @property {Object} info - 订单信息
		 * @property {Object} select_r - 退款原因
		 * @property {Array} images - 退款凭证
		 * @property {Object} form - 退款表单
		 * @property {String} form.refund_price - 退款金额
		 * @property {String} form.content - 退款原因
		 */
		data() {
			return {
				info:{},
				select_r:{},
				images:[],
				form:{
					refund_price:'',
					content:''
				}
			}
		},
		onShow() {
			
		},
		methods: {
			showReturnPopup(){
				this.$refs.retPayPopupRef.open()
			},
			closeRetSuccessPopup() {
				this.$refs.retSuccessPopupRef.close()
				uni.navigateBack({
					delta:2
				})
			},
			
			uploadPZ(){
				uni.chooseImage({
					count:'1',
					success: (res) => {
						let file = res.tempFilePaths[0]
						upload({file}).then(data=>{
							let url = data.data.url
							this.images.push(url)
						})
					}
				})
			},
			
			delimg(i){
				this.images.splice(i,1)
			},
			
			confirm(val){
				this.select_r = val
			},
			
			submit(){
				if(!this.select_r.id){
					uni.showToast({
						title:'请输入退款原因',
						icon:'none'
					})
					return
				}
				let formData = new FormData()
				formData.append('id',this.info.id)
				formData.append('images',this.images.join(','))
				formData.append('refund_reason_id',this.select_r.id)
				formData.append('type','refund')
				formData.append('refund_price',this.form.refund_price)
				formData.append('content',this.form.content)
				
				uni.showLoading()
				refundorder(formData.getData()).then(res=>{
					uni.hideLoading()
					if(res.code==1){
						this.$refs.retSuccessPopupRef.open()
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.return-order-container {
		padding: 22rpx;
		padding-bottom: 176rpx;
	}

	.card-box {
		background: #FFFFFF;
		border-radius: 20rpx;
		padding: 22rpx;
	}
	
	.upload-list{
		display: flex;
		flex-wrap: wrap;
		.upload-image:not(:nth-child(4n)){
			margin-right: 20rpx;
		}
		.upload-image{
			position: relative;
		}
		.del{
			width: 40rpx;
			height: 40rpx;
			position: absolute;
			right: 0;
			top: 0;
			transform: translateX(50%) translateY(-50%);
		}
	}

	.goods-image {
		width: 180rpx;
		height: 180rpx;
		overflow: hidden;
		border-radius: 20rpx;
	}

	.goods-info {
		margin-left: 24rpx;
		flex: 1;
	}
	
	.title {
		font-weight: bold;
		font-size: 34rpx;
		color: #000000;
	}
	
	.icon-right {
		width: 24rpx;
		height: 24rpx;
		margin-left: 10rpx;
	}
	
	.upload-image {
		width: 146rpx;
		height: 146rpx;
	}
	
	.fixed-box {
		width: 100%;
		padding: 0 30rpx;
		padding-bottom: 60rpx;
		position: fixed;
		left: 0;
		bottom: 0;
	}
	
	.fixed-btn {
		height: 96rpx;
		width: 100%;
		border-radius: 96rpx;
		font-weight: bold;
		font-size: 36rpx;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.success-popup {
		width: 560rpx;
		height: 360rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		
		.title {
			font-weight: bold;
			font-size: 36rpx;
			color: #333333;
			padding-top: 40rpx;
		}
		
		.content {
			font-weight: bold;
			font-size: 30rpx;
			color: #333333;
			padding: 48rpx 0;
		}
		
		.confirm-btn {
			width: 264rpx;
			height: 96rpx;
			border-radius: 48rpx;
			font-weight: bold;
			font-size: 32rpx;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
</style>